import time

from selenium.webdriver.common.by import By


class PageBackendGoodsDelete():
    def __init__(self, driver):
        self.driver = driver

# 输入'飞机'点击搜索，查看商品
    def ele_search_name(self):
        self.driver.find_element(By.NAME, 'keyword').send_keys('飞机')

     #点击【搜索】按钮
    def ele_search_submit(self):
        self.driver.find_element(By.CLASS_NAME, 'button').click()
        time.sleep(2)

    #点击【删除】按钮（删除搜索出来的商品）
    def ele_delete_goods(self):
        self.driver.find_element(By.XPATH, '//div[@id="listDiv"]/table[1]/tbody/tr[3]/td[11]/a[4]/img').click()

    #点击弹窗【确认】按钮
    def ele_accept_delete(self):
        self.driver.switch_to.alert.accept()
        self.driver.switch_to.default_content()

        # 进入右侧mainframe
    def ele_main_frame(self):
        self.driver.switch_to.frame('main-frame')

        # 退出frame
    def ele_frame_out(self):
        self.driver.switch_to.default_content()

    def delete_goods(self):
        self.ele_main_frame()
        self.ele_search_name()
        self.ele_search_submit()
        self.ele_delete_goods()
        self.ele_accept_delete()
        self.ele_frame_out()